{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "rubber-brand",
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "#1.指定url\n",
    "url='https://www.sogou.com/'\n",
    "#2.发起请求get方法发的返回值为响应对象\n",
    "response=requests.get(url=url)\n",
    "#3.获取相应数据\n",
    "page_text=response.text\n",
    "#4.持久化存储\n",
    "with open('E:/爬虫代码/souhu/sougou.html','w',encoding='utf-8')as fp:\n",
    "    fp.write(page_text)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "ambient-batch",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "inter a key word周杰伦\n"
     ]
    }
   ],
   "source": [
    "#实现简易网页采集器，对指定不同的关键字进行爬取\n",
    "keyWord=input('inter a key word')\n",
    "#携带请求参数url,如果想爬取不同关键字对应的页面，我们需要将参数url进行动态化\n",
    "#实现参数动态话,parqms参数：保存请求时携带的参数\n",
    "parqms={\n",
    "    'query':keyWord\n",
    "}\n",
    "url='https://www.sogou.com/web?query=zhou&_asf=www.sogou.com&_ast=&w=01019900&p=40040100&ie=utf8&from=index-nologin&s_from=index&sut=2858&sst0=1616305831070&lkt=4%2C1616305828212%2C1616305829179&sugsuv=1616305406346380&sugtime=1616305831070'\n",
    "response=requests.get(url=url)\n",
    "#encoding防止乱码\n",
    "response.encoding='utf-8'\n",
    "page_text=response.text\n",
    "\n",
    "with open('E:/爬虫代码/souhu/zhou.html','w',encoding='utf-8')as fp:\n",
    "    fp.write(page_text)\n",
    "    \n",
    "#异常访问请求，意味着是爬虫而不是正常浏览。通过user-agent判定\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "interesting-funeral",
   "metadata": {},
   "outputs": [],
   "source": [
    "#实现简易网页采集器，对指定不同的关键字进行爬取\n",
    "keyWord=input('inter a key word')\n",
    "#携带请求参数url,如果想爬取不同关键字对应的页面，我们需要将参数url进行动态化\n",
    "#实现参数动态话,parqms参数：保存请求时携带的参数\n",
    "parqms={\n",
    "    'query':keyWord\n",
    "}\n",
    "url='http://125.35.6.84:81/xk/'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "suspended-patio",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
